package algorithms;

import exceptions.CharNoKeyException;

public enum Key {
    A('A', 'Z'), B('B','Y'), C('C', 'X'), D('D', 'W'), E('E', 'V'), F('F', 'U'), G('G', 'T'), H('H', 'S'), I('I', 'R'), J('J', 'Q'), K('K', 'P'), L('L', 'O'), M('M', 'N'), N('N', 'M'), O('O', 'L'), P(
	    'P', 'K'), Q('Q', 'J'), R('R', 'I'), S('S', 'H'), T('T', 'G'), U('U', 'F'), V('V', 'E'), W('W', 'D'), X('X', 'C'), Y('Y', 'B'), Z('Z', 'A');

    private final char key;
    private final char reciprocalKey;

    Key(char key, char reciprocalKey) {
	this.key = key;
	this.reciprocalKey = reciprocalKey;
    }

    public char getKey() {
	return key;
    }

    public char getReciprocalKey() {
	return reciprocalKey;
    }

    public char KeyToChar(Key key) {
	return key.getKey();
    }

    public static Key charToKey(char charKey) {
	switch (charKey) {
	    case 'A':
	    case 'a':
		return Key.A;
	    case 'B':
	    case 'b':
		return Key.B;
	    case 'C':
	    case 'c':
		return Key.C;
	    case 'D':
	    case 'd':
		return Key.D;
	    case 'E':
	    case 'e':
		return Key.E;
	    case 'F':
	    case 'f':
		return Key.F;
	    case 'G':
	    case 'g':
		return Key.G;
	    case 'H':
	    case 'h':
		return Key.H;
	    case 'I':
	    case 'i':
		return Key.I;
	    case 'J':
	    case 'j':
		return Key.J;
	    case 'K':
	    case 'k':
		return Key.K;
	    case 'L':
	    case 'l':
		return Key.L;
	    case 'M':
	    case 'm':
		return Key.M;
	    case 'N':
	    case 'n':
		return Key.N;
	    case 'O':
	    case 'o':
		return Key.O;
	    case 'P':
	    case 'p':
		return Key.P;
	    case 'Q':
	    case 'q':
		return Key.Q;
	    case 'R':
	    case 'r':
		return Key.R;
	    case 'S':
	    case 's':
		return Key.S;
	    case 'T':
	    case 't':
		return Key.T;
	    case 'U':
	    case 'u':
		return Key.U;
	    case 'V':
	    case 'v':
		return Key.V;
	    case 'W':
	    case 'w':
		return Key.W;
	    case 'X':
	    case 'x':
		return Key.X;
	    case 'Y':
	    case 'y':
		return Key.Y;
	    case 'Z':
	    case 'z':
	    case ' ':
		return Key.Z;
	    default:
		throw new CharNoKeyException(charKey);
	}
    }
}
